# coding: utf-8

import json

from flask_wtf import FlaskForm
from wtforms.validators import DataRequired, Optional
from wtforms import DecimalField, StringField

from app.forms import NonValidatingSelectField
from app.products.constant import (
    SceneType, ColorType, Transport, AssembleWay,
    InstallWay, SPACING_LIST, WorkingCondition)


class CalPriceForm(FlaskForm):
    scene_type = NonValidatingSelectField(
        '环境', choices=SceneType.mapping.items(), coerce=int
    )
    color = NonValidatingSelectField(
        '颜色', choices=ColorType.mapping.items(), coerce=int
    )

    transport = NonValidatingSelectField(
        '信号传输方式', choices=Transport.mapping.items(), coerce=int
    )

    assemble_way = NonValidatingSelectField(
        '使用箱体', choices=AssembleWay.mapping.items(), coerce=int
    )
    high = DecimalField('屏体高(m)', validators=[DataRequired()])
    wide = DecimalField('屏体宽(m)', validators=[DataRequired()])
    spacing = NonValidatingSelectField(
        '间距', choices=[(i, 'P{}'.format(i)) for i in SPACING_LIST]
    )
    ground_high = DecimalField('离地高度', validators=[Optional()], default=0)

    install_way = NonValidatingSelectField(
        '安装方式', choices=InstallWay.mapping.items(), coerce=int
    )

    working = NonValidatingSelectField(
        '工况', choices=WorkingCondition.mapping.items(), coerce=int
    )
    products = StringField(default=json.dumps(dict()))
